<template>
  <div class="liteflow-editor-basic">
    <div class="liteflow-editor-basic__title">EL表达式:</div>
    <div class="liteflow-editor-basic__content">
      <pre>{{ elString }}</pre>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref, inject, onBeforeUnmount } from 'vue';
import { GRAPH_SYMBOL } from '../context.js';
import { getModel } from '../../core/state/model.js';

export default defineComponent({
  name: 'Basic',
  setup() {
    const { flowGraph } = inject(GRAPH_SYMBOL);
    const elString = ref(getModel()?.toEL(' ') || '');

    const updateEL = () => {
      const model = getModel();
      const newEL = model?.toEL(' ') || '';
      console.log('[Basic] EL 表达式更新:', newEL);
      elString.value = newEL;
    };

    // 使用 model:changed 事件而不是 model:change，因为 resetCells 不会清除这个监听器
    if (flowGraph.value) {
      flowGraph.value.on('model:changed', updateEL);
    }
    
    onBeforeUnmount(() => {
      if (flowGraph.value) {
        flowGraph.value.off('model:changed', updateEL);
      }
    });

    return {
      elString,
    };
  },
});
</script>

<style lang="less" scoped>
.liteflow-editor-basic {
  padding: 16px;
  
  &__title {
    font-size: 14px;
    font-weight: 600;
    color: #1f2d3d;
    margin-bottom: 12px;
  }
  
  &__content {
    background: #f5f7fb;
    border-radius: 4px;
    padding: 12px;
    max-height: 500px;
    overflow: auto;
    
    pre {
      margin: 0;
      font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
      font-size: 13px;
      line-height: 1.6;
      color: #2c3e50;
      white-space: pre-wrap;
      word-wrap: break-word;
    }
  }
}
</style>
